package com.yzg.sign.project.controller;

import com.yzg.sign.project.common.Result;
import com.yzg.sign.project.domain.SysUser;
import com.yzg.sign.project.request.LoginForm;
import com.yzg.sign.project.request.UpdateUserInfoRequest;
import com.yzg.sign.project.service.CustomerService;
import com.yzg.sign.project.service.SysUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/api/auth")
@Api(value = "/api/auth" ,tags = {"登录接口"})
public class AuthController
{
      @Autowired
      private SysUserService userService;

    @Autowired
    private CustomerService customerService;


    @PostMapping("/sign_in")
    @ApiOperation(value = "用户登录", notes = "用户登录")
    public Result<String> signIn(@RequestBody  LoginForm loginForm)
    {

        return userService.loginByPassword(loginForm);
    }



    @GetMapping("/me")
    @ApiOperation(value = "用户个人信息", notes = "用户个人信息")
    @RequiresAuthentication
    public Result<SysUser> info()
    {
        return userService.getUserInfo();
    }



    @PostMapping("/login_out")
    @ApiOperation(value = "用户登录", notes = "用户登录")
    public Result<String> loginOut()
    {
       return  userService.loginOut();
    }




    @PostMapping("/code2Session")
    @ApiOperation(value = "微信登录", notes = "微信登录")
    public Result<Map<String, String>> code2Session(String code)
    {
        return customerService.code2Session(code);
    }



    @PostMapping("/updateUserInfo")
    @ApiOperation(value = "修改用户的信息", notes = "修改用户的信息")
    public Result<String> updateUserInfo(@RequestBody UpdateUserInfoRequest request)
    {

        return customerService.updateUserInfo(request);
    }



}
